package org.chen.spring.cloud.finchley.zuul;
import com.netflix.zuul.FilterFileManager;
import com.netflix.zuul.FilterLoader;
import com.netflix.zuul.groovy.GroovyCompiler;
import com.netflix.zuul.groovy.GroovyFileFilter;
import com.netflix.zuul.monitoring.MonitoringHelper;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.stereotype.Component;

/**
 * @author chensj
 * @date 2020-02-08 17:19
 */
@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class ZuulServerApplication {
  public static void main(String[] args) {
    SpringApplication.run(ZuulServerApplication.class, args);
  }

  @Component
  public static class GroovyRunner implements CommandLineRunner{

    @Override
    public void run(String... args) throws Exception {
      MonitoringHelper.initMocks();
      FilterLoader.getInstance().setCompiler(new GroovyCompiler());
      FilterFileManager.setFilenameFilter(new GroovyFileFilter());
      // 每5s扫描指定目录
      FilterFileManager.init(
          5,
          "G:\\01_code\\cloud\\chen.dev.learn.demo\\spring-cloud-finchley-all\\spring-cloud-finchley-zuul\\ch7-2-filter\\ch7-2-zuul-server\\src\\main\\java\\org\\chen\\spring\\cloud\\finchley\\zuul\\groovy\\");
    }
  }
}
